
********************************************************************
********************************************************************
****PROJECT E-WELLBEING:INTERNET USE AND WELLBEING IN EUROPE********
********************************************************************
********************************************************************

**Paper: Is Too Much Time on the Internet Making us Less Satisifed with Life? 
**Authors: Ana Suárez-Álvarez & María R. Vicente
**Journal: Applied Research in Quality of Life 

******************************
*CHOOSE THE RIGHT DIRECTORY*
******************************
cd "C:\Users\Yourdirectory"
use ESS_8_9_10.dta, clear


*We Keep only the 21 Countries that are available in the three rounds

keep if cntry== "AT" | cntry== "BE" |cntry== "CH" |cntry== "CZ" |cntry== "DE" |cntry== "EE" |cntry== "ES" |cntry== "FI" |cntry== "FR" |cntry== "GB" |cntry== "HU" |cntry== "IE" |cntry== "IS" |cntry== "IT" |cntry== "LT" |cntry== "NL" |cntry== "NO" |cntry== "PL" |cntry== "PT" |cntry== "SE" |cntry== "SI"
*We include data on internet speed. 
merge m:1 region essround using speed_all.dta 
drop if _merge==1
drop _merge

**********************
**#*DATA PREPARATION*
**********************

**************************************************************************************************
*It is important to weight data using "anweight" -see "ESS_weighting_data_1_1.pdf" for more info. 
**************************************************************************************************
destring anweight, replace
*Gen a numerical variable for each country
encode cntry, gen(ctry)
count

sort essround
by essround: count

*DEPENDENT VARIABLE: LIFE SATISFACTION

sum stflife [aweight = anweight] //How satisfied with life as a whole, from 0 extremely dissatisfied to 10 extremely satisfied.

gen hampered=(hlthhm<3)

label define hamplab 0 "No hampered" 1 "Hampered"
label values hampered hamplab 
gen livingpartner=(rshipa2==1 | rshipa3==1| rshipa4==1| rshipa5==1| rshipa6==1| rshipa7==1| rshipa8==1| rshipa9==1| rshipa10==1| rshipa11==1| rshipa12==1| rshipa13==1| rshipa14==1| rshipa15==1)	
label define partlab 0 "No" 1 "Yes"
label values livingpartner partlab
gen female=(gndr==2)
label define fem 0 "Male" 1 "Female"
label values female fem
sum agea [aweight = anweight] // age of respondent 
tab eisced [aweight = anweight] 
gen employed=pdwrk //Dummy 1 working 0 not working
label define emplab 0 "No" 1 "Yes"
label values employed emplab
sum emprel [aweight = anweight]  //Status in employment 1 employee 2 self-employed 3 family business
gen hhdecile=hinctnta //household income decile: subjetive 
sum hhdecile
sum hincfel [aweight = anweight]  // feelings about hh's income
tab domicil [aweight = anweight] //subjective habitat: respondent's description


*Recode deciles to take acount dk/da
gen decile_r=(hhdecile>5)
replace decile_r=2 if hhdecile==.a |hhdecile==.b| hhdecile==.c
tab decile_r
label define decil 0 "at most 5th decile" 1 "more than 5th decile" 2 "dk/da"
label values decile_r decil
tab decile_r hincfel, V chi
pwcorr hhdecile hincfel, star (0.01)

*Generate dummy variables
gen rural=(domicil>3) //living country village or home in countryside
gen badhealth=(health>2) //fair bad and very bad health
label define heallab 0 "No" 1 "Yes"
label values badhealth heallab

gen badhincfel=(hincfel>2) // difficult/very difficult on present income
tab rural
gen more_5decile=(decile_r==1) // Richest 50%
tab eisced, gen(estu)
gen tertiary=(eisced==6|eisced==7)
gen facetoface=(completion_mode==0)
gen dif_income=(hincfel>2)
tab essround, gen(round_)
tab cntry, gen (c_)

*****Internet time**********:
tab daily_internet
sum internet_time
replace internet_time=. if daily_internet==0

*log de time
gen ln_time = ln(internet_time)

*Top coding of internet_time to max 960**********Máximo 16 h de 24 en internet.
recode internet_time (1000/1440=960)



drop if missing(agea) 
drop if missing(domicil) 
drop if missing(stflife) 
drop if missing(hincfel) 
drop if missing(eisced) 
drop if missing(health) 
drop if missing(female)

* trstlgl - Trust in the legal system
* trstplc - Trust in the police
* trstplt - Trust in politicians

gen instrust = trstlgl + trstplc + trstplt // Va de 0 a 30 
drop if missing(instrust)

recode agea (1/24 =1) (25/45 =2) (46/65 =3) (66/100=4), gen(agegroup)
label define groupage 1 "<25" 2 "25-45" 3 "46-65" 4 ">65"
label values agegroup groupage

recode isco08 (0/310 =1) (1000/3522 =3) (4000/8350=2) (9000/9629=1) , gen(occu_skill) //Los grupos se hacen así siguiendo las indicaciones de ILO
label define skill 1 "Low" 2 "Medium" 3 "High" 
label values occu_skill skill
tab occu_skill
drop if missing(occu_skill)
drop if missing(internet_time)
drop if missing(sclmeet)
drop if missing(rlgdgr)
drop if missing(inprdsc)
tab domicil, gen(dom_)
tab decile_r, gen(de_)
tab occu_skill, gen(occu_)
tab hincfel, gen(hhinc_)


generate hhinc = hincfel
replace hhinc = 3 if hincfel==4
label define inco 1 "Living confortably" 2 "Can cope" 3 "Having difficulties" 
label values hhinc inco

recode instrust (0/10 =1) (11/20 =2) (20/30=3) , gen(trusint)
label define truslab 1 "Low" 2 "Medium" 3 "High"
label values trusint truslab

recode sclmeet (1/4=1) (5=2) (6/7=3), gen(meetpeop)
label define labmeet 1 "<= 1 a month " 2 ">= 1 a month" 3 ">= 1 a week"
label values meetpeop labmeet

recode inprdsc (0/1=1) (2/3=2) (4/6=3), gen(discuss)
label define discmat 1 "None or 1" 2 "2-3 people" 3 "More than 4"
label values discuss discmat

recode lrscale (0/4=1) (5=2) (6/10=3), gen (politics)
label define polab 1 "Left" 2 "Netural" 3 "Right"
label values politics polab

recode rlgdgr (0/4=1) (5=2) (6/10=3), gen (religion)
label define rellab 1 "No/Low religiosity" 2 "Netural" 3 "High religiosity"
label values religion rellab


label define rtrdlab 0 "No" 1 "Yes"
label values rtrd rtrdlab

xtile time = internet_time [aweight = anweight], nquantiles(4) //Quartiles

tab time, gen(tim_) //Dummies quartiles


************************************************
**DESCRIPTIVES
************************************************

bysort essround: asdoc tabstat  stflife internet_time avg_d female employed rtrd agea livingpartner sclmeet inprdsc badhealth hampered dom_* de_* hhinc_* rural hincfel  eisced tertiary occu_* lrscale rlgdgr instrust [aweight = anweight] , stat(mean sd) save(descrip_rounds.doc) replace

bysort time: asdoc tabstat  stflife internet_time avg_d  female employed rtrd agea livingpartner sclmeet inprdsc badhealth hampered dom_* de_* hhinc_* rural hincfel  eisced tertiary occu_* lrscale rlgdgr instrust [aweight = anweight], stat(mean sd) save(descrip_timecuartil.doc) replace

distplot internet_time [aweight = anweight], over(placeliving) xtitle("Internet time") title("Domicile") scheme(s2mono) name(domicil) 
distplot internet_time [aweight = anweight], over(agegroup) xtitle("Internet time") title("Age Group") scheme(s2mono) name(agegroup)
distplot internet_time [aweight = anweight], over(female) xtitle("Internet time") title("Gender") scheme(s2mono) name(female)
distplot internet_time [aweight = anweight], over(hampered) xtitle("Internet time") title("Hampered individuals") scheme(s2mono) name(hampered) 

distplot internet_time [aweight = anweight], over(badhealth) xtitle("Internet time") title("Bad health status") scheme(s2mono) name(health)
distplot internet_time [aweight = anweight], over(rtrd) xtitle("Internet time") title("Retired") scheme(s2mono) name(retired)
distplot internet_time [aweight = anweight], over(employed) xtitle("Internet time") title("Employed") scheme(s2mono) name(employed)
distplot internet_time [aweight = anweight], over(livingpartner) xtitle("Internet time") title("Living with partner") scheme(s2mono) name(partner)

distplot internet_time [aweight = anweight], over(educ3) xtitle("Internet time") title("Educational level") scheme(s2mono) name(education)
distplot internet_time [aweight = anweight], over(occu_skill) xtitle("Internet time") title("Occupations' skills") scheme(s2mono) name(skill)
distplot internet_time [aweight = anweight], over(hhinc) xtitle("Internet time") title("HHs subjective income") scheme(s2mono) name(income)
distplot internet_time [aweight = anweight], over(trusint) xtitle("Internet time") title("Institutional trust") scheme(s2mono) name(trusint)

distplot internet_time [aweight = anweight], over(discuss) xtitle("Internet time") title("N. people discuss personal matters") scheme(s2mono) name(discuss)
distplot internet_time [aweight = anweight], over(meetpeop) xtitle("Internet time") title("Meet with friends") scheme(s2mono) name(meetings)
distplot internet_time [aweight = anweight], over(religion) xtitle("Internet time") title("Religiosity") scheme(s2mono) name(religion)
distplot internet_time [aweight = anweight], over(politics) xtitle("Internet time") title("Political ideology") scheme(s2mono) name(politics)


graph combine domicil agegroup female hampered 

graph combine health retired employed partner

graph combine education skill income 

graph combine discuss meetings discuss meetings  

ciplot stflife  [aweight=anweight] , scheme(s2mono) by(time) 


global xmiss "badhealth hampered livingpartner domicil female agea sqage employed rtrd occu_skill hincfel eisced instrust lrscale rlgdgr sclmeet inprdsc round_* c_*"
foreach var of varlist $xmiss{
count if missing(`var')
drop if missing(`var')
}

*****ESTIMATIONS OF MODELS A & B*********
cmp setup
global x1_t "agea rural employed rtrd sclmeet inprdsc occu_3 eisced avg_d i.hincfel round_* c_* "
global x1_wb "badhealth hampered livingpartner rural female agea sqage employed rtrd occu_3 i.hincfel eisced instrust rlgdgr lrscale sclmeet inprdsc round_* c_*" 

*For internet time:
cmp (stflife= internet_time  $x1_wb ) (internet_time= $x1_t) [aweight = anweight], ind($cmp_cont $cmp_cont) nonrtolerance vce(cluster cntry)	
estimates store a4

*For Q4
cmp (stflife= tim_4  $x1_wb ) (tim_4= $x1_t) [aweight = anweight], ind($cmp_cont $cmp_probit) nonrtolerance vce(cluster cntry)	
